<?php

/**
 * Project: Espolon
 * Licence: BSD License
 * Link: http://espolon.org/
 * Copyright: Nicolas de Bari Embriz Garcia Rojas <nbari at espolon dot org>
 * Author: Nicolas de Bari Embriz Garcia Rojas <nbari at espolon dot org>
 * Version: Beta
 */

if (!defined('SITE_ROOT')) exit('No direct script access allowed');

class Config extends Dispatcher {
  private $default_mode;
  private $languages;
  private $themes;
  private $default_template;
  private $site_name;
  private $email_from;
  private $email_fromname;
  private $avoid_loggin_twice;
  private $allow_force_login;
  private $msg;
  private $msgid;
  private $podb_id;

  function setMsg ($msg) { $this->msg = $msg; }
  function setLanguages ($languages) { $this->languages = $languages; }
  function setThemes ($themes) { $this->themes = $themes; }
  function setMsgid ($msgid) { $this->msgid = $msgid; }
  function setPodb_id ($podb_id) {$this->podb_id = $podb_id; }

  function getMsg() { return $this->msg; }
  function getLanguages () { return $this->languages; }
  function getThemes () { return $this->themes; }
  function getMsgid() { return $this->msgid; }
  function getPodb_id() { return $this->podb_id; }

  function SaveConfig ($config) {
    foreach ($config as $key => $value) {
      if($key != 'btn_Submit') {
        $rs = $this->getDb()->Execute("UPDATE core_config SET config_value='$value' WHERE config_name='$key'");
      }
    }
  }

  function checkExistsPodb($op) {
    switch($op) {
      case 'add':
        return ($this->getDb()->GetAll("SELECT * FROM core_podb WHERE msgid='".$this->getMsgid()."'")) ? false : true;
      break;
      case 'modify':
        return ($this->getDb()->GetAll("SELECT * FROM core_podb WHERE msgid='".$this->getMsgid()."' AND id !='".$this->getPodb_id()."'")) ? false : true;
      break;
    }
  }

  function addMsgid($values) {
    $data['msgid']  = $values['msgid'];
    $data['msgstr'] = $values['msgstr'];
    $rs = $this->getDb()->AutoExecute('core_podb', $data, 'INSERT');
    if(!$rs) { $this->setMsg($this->getDb()->ErrorMsg()); }
  }

  function modifyMsgid($values) {
    $data['msgid']  = $values['msgid'];
    $data['msgstr'] = $values['msgstr'];
    $rs = $this->getDb()->AutoExecute('core_podb', $data, 'UPDATE', "id=".$this->getPodb_id()."");
    if(!$rs) { $this->setMsg($this->getDb()->ErrorMsg()); }
  }

  function getPo($id) {
    return $this->getDb()->GetRow("SELECT * FROM core_podb WHERE id=$id");
  }

}
?>